package com.boarsoft.boar.batch.demo.flow;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.boarsoft.flow.core.SimpleFlowEngine;
import com.boarsoft.flow.core.bean.ProcessHandler;

/**
 * 此类为根据 状态码（data参数）或者 异常（Throwable参数）<br>
 * 来显式调起冲正的通用或半通用处理节点示例
 * 
 * @author Mac_J
 *
 */
public class DemoReveseHandler implements ProcessHandler {
	@Autowired
	protected SimpleFlowEngine engine;

	@SuppressWarnings("unchecked")
	@Override
	public Object process(String entry, Object data, Throwable throwable) throws Throwable {
		Map<String, Object> m = (Map<String, Object>) data;
		String rc = (String) m.get("responseCode");
		if (!"000000".equals(rc)) {
			// 此处的flowId和entry可以来自程序中写死的值，也可以是前面步骤传递过来的参数或节点参数，又或来自其它形式
			engine.start("flowId", data, "entry");
		}
		return rc;
	}

}
